﻿using AntaresShell.Localization;
using AntaresShell.Logger;
using System;
using System.Collections.Generic;
using Windows.ApplicationModel;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Text;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Antares.VIEWs
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class HelpPage
    {
        public HelpPage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="navigationParameter"></param>
        /// <param name="pageState"></param>
        protected async override void LoadState(object navigationParameter, Dictionary<string, object> pageState)
        {
            try
            {
                StorageFile file;
                switch (LanguageProvider.CurrentLanguage.ToLower())
                {
                    case "vi":
                        file = await Package.Current.InstalledLocation.GetFileAsync("Help-vi-VN.rtf");
                        break;
                    case "ja":
                        file = await Package.Current.InstalledLocation.GetFileAsync("Help-ja-JP.rtf");
                        break;
                    default:
                        file = await Package.Current.InstalledLocation.GetFileAsync("Help-en-US.rtf");
                        break;
                }

                IRandomAccessStream randAccStream = await file.OpenAsync(FileAccessMode.Read);
                RichBox.Document.LoadFromStream(TextSetOptions.FormatRtf, randAccStream);
                
            }
            catch (Exception ex)
            {
                LogManager.Instance.LogException(ex.ToString());
            }
        }
    }
}
